package com.atguigu.day18.homework.h2;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/22 21:16
 * @注释
 */
public class StudentTest {
    @Test
    public void test01(){
        ArrayList<Student> students = new ArrayList<>();
        Student s1 = new Student("谢霆锋", 85);
        Student s2 = new Student("章子怡", 63);
        Student s3 = new Student("刘亦菲", 77);
        Student s4 = new Student("黄晓明", 33);
        Student s5 = new Student("岑小村", 92);
        Collections.addAll(students, s1, s2, s3, s4, s5);

        //匿名内部类
        /*Collections.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return Double.compare(o1.getScore(), o2.getScore());
            }
        });
        for (Student student : students) {
            System.out.println(student);
        }*/
        //Lambda
        /*Collections.sort(students,
                (o1,o2)-> Double.compare(o1.getScore(), o2.getScore()));
        for (Student student : students) {
            System.out.println(student);
        }*/
        //方法引用

        Collections.sort(students,Comparator.comparing(Student::getScore));
        for(Student student : students){
            System.out.println(student);
        }

    }
}
